#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

long long countSubarrays(int* nums, int numsSize, int k) {
    int max = 0, count = 0;
    long long sum = 0;
    for (int i = 0; i < numsSize; i++)
    {
        if (nums[i] > max)
            max = nums[i];
    }
    for (int left = 0; left < numsSize; left++)
    {
        count = 0;
        int right = left;
        while (right < numsSize)
        {
            if (nums[right] == max)
                count++;
            if (count == k)
            {
                sum += numsSize - right;
                break;
            }
            right++;
        }
    }
    return sum;
}


int main()
{
    int nums[5] = { 1,3,2,3,3 };
   int ret= countSubarrays(nums, 5, 2);
   printf("%d", ret);
   return 0;
}